using System;
using System.ComponentModel;
using System.Windows.Forms;
using SubtextSmiliesPlugin.Properties;

namespace SubtextSmiliesPlugin
{
	/// <summary>
	/// Summary description for SubtextSmiliesControl.
	/// </summary>
	public class SubtextSmiliesControl : UserControl
    {
        private ListView listView1;
        private ImageList imageList1;
        private IContainer components;

		public event EventHandler MessageChanged;

		public SubtextSmiliesControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("", "evil.gif");
            System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("", "frown.gif");
            System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("", "happy.gif");
            System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("", "mad.gif");
            System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem("", "openmouth.gif");
            System.Windows.Forms.ListViewItem listViewItem6 = new System.Windows.Forms.ListViewItem("", "speechless.gif");
            System.Windows.Forms.ListViewItem listViewItem7 = new System.Windows.Forms.ListViewItem("", "tongue.gif");
            System.Windows.Forms.ListViewItem listViewItem8 = new System.Windows.Forms.ListViewItem("", "unhappy.gif");
            System.Windows.Forms.ListViewItem listViewItem9 = new System.Windows.Forms.ListViewItem("", "veryhappy.gif");
            System.Windows.Forms.ListViewItem listViewItem10 = new System.Windows.Forms.ListViewItem("", "wink.gif");
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SubtextSmiliesControl));
            this.listView1 = new System.Windows.Forms.ListView();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.SuspendLayout();
            // 
            // listView1
            // 
            this.listView1.Activation = System.Windows.Forms.ItemActivation.OneClick;
            this.listView1.Alignment = System.Windows.Forms.ListViewAlignment.Left;
            this.listView1.Cursor = System.Windows.Forms.Cursors.Hand;
            this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.listView1.HotTracking = true;
            this.listView1.HoverSelection = true;
            listViewItem1.StateImageIndex = 0;
            listViewItem1.ToolTipText = "Evil";
            listViewItem1.UseItemStyleForSubItems = false;
            listViewItem2.StateImageIndex = 0;
            listViewItem2.ToolTipText = "Frown";
            listViewItem3.StateImageIndex = 0;
            listViewItem3.ToolTipText = "Happy";
            listViewItem4.StateImageIndex = 0;
            listViewItem4.ToolTipText = "Mad";
            listViewItem5.StateImageIndex = 0;
            listViewItem5.ToolTipText = "Openmouth";
            listViewItem6.StateImageIndex = 0;
            listViewItem6.ToolTipText = "Speechless";
            listViewItem7.StateImageIndex = 0;
            listViewItem7.ToolTipText = "Tongue";
            listViewItem8.StateImageIndex = 0;
            listViewItem8.ToolTipText = "Unhappy";
            listViewItem9.StateImageIndex = 0;
            listViewItem9.ToolTipText = "Very happy";
            listViewItem10.StateImageIndex = 0;
            listViewItem10.ToolTipText = "Wink";
            this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
            listViewItem1,
            listViewItem2,
            listViewItem3,
            listViewItem4,
            listViewItem5,
            listViewItem6,
            listViewItem7,
            listViewItem8,
            listViewItem9,
            listViewItem10});
            this.listView1.LargeImageList = this.imageList1;
            this.listView1.Location = new System.Drawing.Point(0, 0);
            this.listView1.Margin = new System.Windows.Forms.Padding(0);
            this.listView1.MultiSelect = false;
            this.listView1.Name = "listView1";
            this.listView1.Size = new System.Drawing.Size(127, 87);
            this.listView1.SmallImageList = this.imageList1;
            this.listView1.TabIndex = 23;
            this.listView1.TileSize = new System.Drawing.Size(30, 25);
            this.listView1.UseCompatibleStateImageBehavior = false;
            this.listView1.View = System.Windows.Forms.View.Tile;
            this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.SubtextSmiliesControl_MouseClick);
            // 
            // imageList1
            // 
            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
            this.imageList1.Images.SetKeyName(0, "evil.gif");
            this.imageList1.Images.SetKeyName(1, "frown.gif");
            this.imageList1.Images.SetKeyName(2, "happy.gif");
            this.imageList1.Images.SetKeyName(3, "mad.gif");
            this.imageList1.Images.SetKeyName(4, "openmouth.gif");
            this.imageList1.Images.SetKeyName(5, "speechless.gif");
            this.imageList1.Images.SetKeyName(6, "tongue.gif");
            this.imageList1.Images.SetKeyName(7, "unhappy.gif");
            this.imageList1.Images.SetKeyName(8, "veryhappy.gif");
            this.imageList1.Images.SetKeyName(9, "wink.gif");
            // 
            // SubtextSmiliesControl
            // 
            this.Controls.Add(this.listView1);
            this.Name = "SubtextSmiliesControl";
            this.Size = new System.Drawing.Size(127, 87);
            this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.SubtextSmiliesControl_MouseClick);
            this.ResumeLayout(false);

		}
		#endregion

		protected virtual void OnMessageChanged(EventArgs e)
		{
			if(MessageChanged != null)
				MessageChanged(this, e);
		}

        public String Message
        {
            get { return "<img " + " src=\"" + SubtextSmilies() + "\">" + "" + "</img>"; }
            set { listView1.Tag = value; }
        }
	    
	    public String SubtextSmilies()
	    {
            string rel = null;
            //http://www.analystdeveloper.com/blogs
            //"Providers/BlogEntryEditor/FCKeditor/editor/images/smiley/msn/"
            //name of the image

            //siteUrl
            rel = Settings.Default.siteURL;

            //check for the trailing back slash
            if (rel.LastIndexOf("/") == rel.Length-1)
                rel = rel.Remove(rel.Length-1, 1);

            rel += "/smilies/";


            ListView.SelectedListViewItemCollection smily =
            this.listView1.SelectedItems;

            foreach (ListViewItem item in smily)
            {
                rel += item.ImageKey;
            }

            return rel;

	    }

        private void SubtextSmiliesControl_MouseClick(object sender, MouseEventArgs e)
        {
            OnMessageChanged(e);
        }
    }
}
